#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef string vextype;
const int n = 8;
int visited[n];
typedef struct AMGraph
{
    vextype vexs[n];
    int arcs[n][n];
    int vexnum, arcnum;
} AMGraph;
struct QueueNode
{
    int val;
    QueueNode *next;
    QueueNode()
    {
        next = NULL;
    }
};
struct Queue
{
    QueueNode *head;
    QueueNode *tail;
    Queue()
    {
        head = NULL;
        tail = NULL;
    }
};
void InitQueue(Queue &Q)
{
}
void EnQueue(Queue &Q, int v)
{

    QueueNode *tmp = new QueueNode();
    tmp->val = v;
    if (Q.tail == NULL)
    {
        Q.tail = tmp;
    }
    if (Q.head == NULL)
    {
        Q.head = tmp;
    }
    if (Q.head != NULL && Q.tail != NULL)
    {
        Q.tail->next = tmp;
        Q.tail = tmp;
    }
}

bool QueueEmpty(Queue &Q)
{
    return Q.head == NULL and Q.tail == NULL;
}

void DeQueue(Queue &Q, int &i)
{
    if (Q.head == Q.tail)
    {
        Q.tail = NULL;
    }
    i = Q.head->val;
    QueueNode *dp = Q.head;
    Q.head = Q.head->next;

    delete dp;
}

#define TRUE 1
#define FALSE 0

void create(AMGraph &G)
{
    G.arcnum = 9;
    G.vexnum = 8;
    for (int i = 0; i < n; i++)
    {
        G.vexs[i] = "v" + to_string(i + 1);
    }
    int ga[8][8] = {
        {0, 1, 1, 0, 0, 0, 0, 0},
        {1, 0, 0, 1, 1, 0, 0, 0},
        {1, 0, 0, 0, 0, 1, 1, 0},
        {0, 1, 0, 0, 0, 0, 0, 1},
        {0, 1, 0, 0, 0, 0, 0, 1},
        {0, 0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 0, 0, 1, 0, 0},
        {0, 0, 0, 1, 1, 0, 0, 0}
    };
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            G.arcs[i][j] = ga[i][j];
        }
        
    }
    
}

void BFS(AMGraph &G, int k)
{
    Queue Q;
    cout << G.vexs[k];
    visited[k] = TRUE;
    EnQueue(Q, k);
    while (!QueueEmpty(Q))
    {
        int i;
        DeQueue(Q, i);
        for (int j = 0; j < G.vexnum; j++){
            if ((G.arcs[i][j] == 1) && (!visited[j]))
            {
                cout << G.vexs[j];
                visited[j] = TRUE;
                EnQueue(Q, j);
            }
        }
    }
}

int main(int argc, char const *argv[])
{
    AMGraph G;
    create(G);
    BFS(G, 0);
    return 0;
}
